import config from "./config.js"
	import moment from "moment"
import {
	ElMessageBox,
	ElMessage
} from 'element-plus'
export default {
	data() {

		return {
			schoollist: [],
			modalState: false,
			copyForm: {},
			tableData: [],
			id: null,
			selectData:null,
			page:1,
			pagesize:15,
			total:100,
			keywords:""
			
		}
	},
	created() {

	},
	watch:{
		selectData(val){
			this.getData();
		}
	},
	methods: {
		//新增初始化
		add() {
		
			Object.keys(this.form).forEach(t => {
				switch (typeof(this.form[t])) {
					case 'string':
						this.form[t] = ''
						break;
					case 'object':
						this.form[t] = [];
						break;
					case 'number':
						this.form[t] = null;
						break;
				}
			})
		
			this.id = null;
			//this.form = this.copyForm;
			this.modalState = true;
			
		
		},
		whatname(id) {
		
			return this.schoollist.find(t => t.id == id)
		},
		getSchoolList(){
			this.$http.post("/index.php/index/Userinfo/schoollist", {
				tokenid: 'nf2021113012336899abc'
			}).then(data => {
				data.push({
					id: "100",
					name: "其他"
				})
				this.schoollist = data
			
			
			})
		},
		initmap(j,w){
			var that=this;
			this.$nextTick(()=>{
				//console.log(BMap)
				var map = new BMap.Map("allmap");
				var geoc = new BMap.Geocoder(); //地址解析对象  
				var markersArray = [];
				var geolocation = new BMap.Geolocation();
				
				
				var point = new BMap.Point(j?j:116.404412, w?w:39.914714);
				map.centerAndZoom(point, 12); // 中心点  
				if(j){
					// var mk = new BMap.Marker(j,w);
					// map.addOverlay(mk);
					// map.panTo(point);
					// map.enableScrollWheelZoom(true);
					addMarker({lng:j,lat:w})
				}else{
					geolocation.getCurrentPosition(function(r) {
						if (this.getStatus() == BMAP_STATUS_SUCCESS) {
							var mk = new BMap.Marker(r.point);
							map.addOverlay(mk);
							map.panTo(r.point);
							map.enableScrollWheelZoom(true);
						} else {
							alert('failed' + this.getStatus());
						}
					}, {
						enableHighAccuracy: true
					})
				}
				
				map.addEventListener("click", showInfo);
				
				
				//清除标识  
				function clearOverlays() {
					if (markersArray) {
						for (var i in markersArray) {
							map.removeOverlay(markersArray[i])
						}
					}
				}
				//地图上标注  
				function addMarker(point) {
					var marker = new BMap.Marker(point);
					markersArray.push(marker);
					clearOverlays();
					map.addOverlay(marker);
				}
				//点击地图时间处理  
				function showInfo(e) {
					
					 that.form.jindu=e.point.lng;
					 that.form.weidu=e.point.lat;
					addMarker(e.point);
				}
			})
		},
		ifType(name){
			return config.matchFileSuffixType(name);
		},
		editimg(file,key){
			console.log(file,key)
			this.form[key]=file.data;
		},
		editimgsProps(file,key,ifkey){
			
			this.$emit("editimgsProps",{file,key,ifkey})
			 this.form[key]=file.data;
		},
		editImgsProps(data){
			console.log(data)
			if(data.ifkey){
				this[data.ifkey][data.key]=data.file.data;
			}else{
				this.form[data.key]=data.file.data;
			}
			
		},
		//验证提交
		doRules(ref) {
			console.log(ref)
			return new Promise((resolve, reject) => {
				//做一些异步操作
				ref.validate((valid) => {
					if (valid) {
						resolve()
					} else {
						reject()

					}
				})
			})

		},
		// 删除弹窗
		removeModal(data) {
			console.log(data)
			ElMessageBox.confirm(
					'是否确定删除?',
					'警告', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning',
					}
				)
				.then(() => {
					this.remove(data);
				})

		},
		//编辑初始化
		edit(data, cb) {
			this.id = data.row.id;	
			// console.log(data,cb)
			cb && cb(data);
			this.form = this.copyObj(data.row);
			// if(this.times!==undefined){
			// 	this.times=moment(this.form.times).format();
			// }
			if(this.static){
				this.static=this.form.static+'';
			}
			this.modalState = true;
			if(this.selectedOptions){
				this.selectedOptions=[data.row.province,data.row.city];
			}
			//BMap?this.initmap(data.row.jindu,data.row.weidu):'';
		},
		//新增初始化
		add() {
            console.log(0)
			Object.keys(this.form).forEach(t => {
				console.log(typeof(this.form[t]))
				switch (typeof(this.form[t])) {
					case 'string':
					   if(this.form[t]){
						   
					   }else{
						   this.form[t] = ''
					   }
						
						break;
					case 'object':
						this.form[t] = [];
						break;
					case 'number':
						this.form[t] = null;
						break;
				}
			})

			this.id = null;
			
			this.modalState = true;
			
			
			
			

		},
		//拷贝对象
		copyObj(obj) {
			return JSON.parse(JSON.stringify(obj));
		},
		//图片前缀
		ifImgHeader(src) {
			return config.img + src
		},
		ifImgHeaders(src) {
			return config.imgs + src
		}
	}
}
